<template>
  <!-- <a
    class="message-location"
    :href="data.href"
    target="_blank"
    title="点击查看详情"
  >
    <span class="el-icon-location-outline">{{ data.description }}</span>
    <img :src="data.url" style="width: 450rpx;height: 300rpx;">
  </a> -->
  <view class="message-location" @click="toWebView">
    <span class="el-icon-location-outline">{{ data.description }}</span>
    <img :src="data.url" style="width: 450rpx;height: 300rpx;">
  </view>
</template>

<script lang="ts" setup>
import { watchEffect, ref } from '../../../../adapter-vue';
const props = defineProps({
  content: {
    type: Object,
    default: () => ({}),
  },
});
const data = ref();
watchEffect(() => {
  data.value = props.content;
});
const toWebView = ()=>{
	let res = getUrlParams(data.value.href)
	console.log(res)
	uni.openLocation({
				latitude: Number(res.pointy),
				longitude: Number(res.pointx),
				name:res.name,
				success: function () {
					console.log('success');
				},
				fail: (err) => {
					console.log(err)
				}
			});
	// uni.navigateTo({
	// 	url:'../../components/TUIChat/web-view?url='+ encodeURIComponent(data.value.href)
	// })
}
const getUrlParams=(url:any)=> {
    // 通过 ? 分割获取后面的参数字符串
    let urlStr = url.split('?')[1]
    // 创建空对象存储参数
    let obj = {};
    // 再通过 & 将每一个参数单独分割出来
    let paramsArr = urlStr.split('&')
    for(let i = 0,len = paramsArr.length;i < len;i++){
        // 再通过 = 将每一个参数分割为 key:value 的形式
        let arr = paramsArr[i].split('=')
        obj[arr[0]] = arr[1];
    }
    return obj
}
</script>
<style lang="scss" scoped>
@import "../../../../assets/styles/common";

.message-location {
  display: flex;
  flex-direction: column;
}
</style>
